Technical Q&A QA1315
Why isn't my edit text box in my Navigation dialog's custom area working on 10.3?


Q: Why isn't my edit text box in my Navigation dialog's custom area working on 10.3?

A: Navigation Services dialogs are now compositing on Mac OS X 10.3. The NavCustomControl / kNavCtlAddControl call now adds (or moves) the control or HIView in the dialog's control list. Previously, the control had to be in the control list already.

Due to a bug, which will be fixed, this NavCustomControl call mishandles the Edit Text control if it was already in the control list. The symptoms are an empty box (even if a string was provided at creation) which doesn't accept typed characters even when the edit box has the focus. There is a simple workaround to this bug which is given below.

Thus, the code which was correct previously:



Listing 1. Previous Code.


CreateEditUnicodeTextControl(callBackParms->window, &bounds,

                    CFSTR("Some Text"), false, NULL, &editText);

NavCustomControl(callBackParms->context, kNavCtlAddControl, editText);




should be changed, for Mac OS X 10.3, into:



Listing 2. New Code.


CreateEditUnicodeTextControl(NULL, &bounds,

                    CFSTR("Some Text"), false, NULL, &editText);

NavCustomControl(callBackParms->context, kNavCtlAddControl, editText);




You may add a check for the version this way:



Listing 3. Checking HIToolbox version.


WindowRef inWindow;

if (GetHIToolboxVersion() < 0x130)

   inWindow = callBackParms->window;

else

   inWindow = NULL;

CreateEditUnicodeTextControl(inWindow, &bounds,

                    CFSTR("Some Text"), false, NULL, &editText);




And you can use the following code to retrieve the HIToolbox version:



Listing 4. Retrieving HIToolbox version.


UInt32 GetHIToolboxVersion()

   {

   CFBundleRef bundle;

   CFStringRef versStr = NULL;

   static UInt32 version = 0;



   // let's do the heavy following code only once...

   if (version != 0) return version;



   bundle = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.HIToolbox"));

   if ( bundle != NULL )

      versStr = (CFStringRef)CFBundleGetValueForInfoDictionaryKey(bundle,

                    CFSTR("CFBundleShortVersionString"));

      if (  versStr != NULL &&

            CFGetTypeID(versStr) == CFStringGetTypeID())

         {

         int major = 0, minor = 0, bugfix = 0;

         char sz[20];



         CFStringGetCString(versStr, sz, sizeof(sz), kCFStringEncodingUTF8);

         sscanf(sz, "%d.%d.%d", &major, &minor, &bugfix);

         version = ( major << 8 ) + ( minor << 4 ) + bugfix;

         }



   return version;

   }




After the bug is fixed, once again enabling the use of callBackParms->window as first parameter of the CreateEditUnicodeTextControl call, the workaround of passing NULL as first parameter will also still work as expected on Mac OS X 10.3 and later.


[Oct 28, 2003]


Developer Documentation | Technical Notes | Development Kits | Sample Code